package com.weyoung.app.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weyoung.app.dto.req.UserHelpAndFeedbackReqDTO;
import com.weyoung.app.mapper.HelpAndFeedbackMapper;
import com.weyoung.app.service.HelpAndFeedbackService;
import com.weyoung.common.consatant.exception.ClientException;
import com.weyoung.common.enums.UserErrorCodeEnum;
import com.weyoung.common.model.entity.HelpAndFeedback;
import org.springframework.stereotype.Service;

@Service
public class HelpAndFeedbackServiceImpl extends ServiceImpl<HelpAndFeedbackMapper, HelpAndFeedback> implements HelpAndFeedbackService {

    @Override
    public void addHelpAndFeedback(UserHelpAndFeedbackReqDTO requestParam) {
        String userId = StpUtil.getLoginId().toString();
        if (userId == null) {
            throw new ClientException(UserErrorCodeEnum.USER_TOKEN_FAIL);
        }
        HelpAndFeedback helpAndFeedback = BeanUtil.toBean(requestParam, HelpAndFeedback.class);
        helpAndFeedback.setUserId(Integer.parseInt(userId));
        baseMapper.insert(helpAndFeedback);
    }
}